package com.stack.wemedia.feign;

import com.stack.apis.wemedia.IWemediaClient;
import com.stack.model.admin.dtos.AdNewsDto;
import com.stack.model.common.dtos.ResponseResult;
import com.stack.model.wemedia.NewsIdVO;
import com.stack.model.wemedia.dtos.WmNewsPageReqDto;
import com.stack.model.wemedia.pojos.WmChannel;
import com.stack.model.wemedia.pojos.WmNews;
import com.stack.model.wemedia.pojos.WmUser;
import com.stack.wemedia.service.WmChannelService;
import com.stack.wemedia.service.WmNewsAutoScanService;
import com.stack.wemedia.service.WmNewsService;
import com.stack.wemedia.service.WmUserService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * @author llz
 * @date 2023/10/11 10:01
 * @description
 */
@RestController
public class WemediaClient implements IWemediaClient {

    @Resource
    private WmChannelService wmChannelService;

    @Resource
    private WmUserService wmUserService;

    @Resource
    private WmNewsService wmNewsService;

    @Resource
    private WmNewsAutoScanService wmNewsAutoScanService;

    /**
     * channel
     */

    @GetMapping("/api/v1/channel/list")
    @Override
    public ResponseResult getChannels() {
        return wmChannelService.findAll();
    }

    @GetMapping("/api/v1/channel/{id}")
    @Override
    public WmChannel getChannelBase(@PathVariable("id") Integer id) {
        return wmChannelService.getById(id);
    }

    @PostMapping("/api/v1/channel/save")
    @Override
    public Boolean saveChannel(@RequestBody WmChannel wmChannel) {
        return wmChannelService.save(wmChannel);
    }

    @PostMapping("/api/v1/channel/updateChannel")
    @Override
    public void updateChannel(@RequestBody WmChannel wmChannel) {
        wmChannelService.updateById(wmChannel);
    }

    /**
     * user
     */

    @GetMapping("/api/v1/user/getUserBase")
    @Override
    public WmUser getUserBase(Integer id){
        return wmUserService.getById(id);
    }


    /**
     *news
     */


    @PostMapping("/api/v1/news/updateNewsById")
    @Override
    public Boolean updateNewsById(@RequestBody WmNews wmNews){
        return wmNewsService.updateById(wmNews);
    }

    @PostMapping("/api/v1/news/getNewsList")
    @Override
    public ResponseResult getNewsList(@RequestBody WmNewsPageReqDto dto) {
        return wmNewsService.getNewsList(dto);
    }

    @PostMapping("/api/v1/news/saveApArticleAndWmNews")
    @Override
    public void saveApArticleAndWmNews(@RequestBody NewsIdVO dto) {
        wmNewsAutoScanService.autoScanWmNews(dto.getId());
    }
}
